package com.example.student.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.constants.RdsConstants;
import com.example.common.domain.pojo.Handouts;
import com.example.common.utils.CacheClient;
import com.example.student.mapper.HandoutsMapper;
import com.example.student.service.HandoutsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class HandoutsServiceImpl extends ServiceImpl<HandoutsMapper, Handouts> implements HandoutsService {

    @Autowired
    private HandoutsMapper handoutsMapper;
    @Autowired
    private CacheClient cacheClient;

//    @Override
//    public Handouts getHandoutsById(String HandoutsId){
//        return handoutsMapper.selectById(HandoutsId);
//    }

    @Override
    public Handouts getHandoutsById(String id) {
        // 使用逻辑过期策略获取讲义信息
        return cacheClient.queryWithLogicalExpire(
                RdsConstants.HANDOUTS_INFO,
                id,
                Handouts.class,
                this::getById, // 使用MyBatis-Plus的基础方法
                RdsConstants.CACHE_NULL_TTL,
                TimeUnit.MINUTES,
                false
        );
    }


}
